package com.mo2323.merchant.controller;

import com.mo2323.common.util.QRCodeUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * @author 高岐
 * @date 2019-03-10.
 */
@Controller
public class CommonController {

    @SuppressWarnings("unused")
    @RequestMapping(value = "/common/qrImage", method = RequestMethod.GET)
    @ResponseBody
    public void getQRImage(@RequestParam(value = "qrCode") String qrCode, HttpServletResponse response) {
        BufferedImage qrImage = QRCodeUtil.createQrCode(qrCode);
        response.setHeader("Content-Type", "image/jpeg");
        try {
            ImageIO.write(qrImage, "png", response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
